package com.skywo.demo1.common.security

import com.alibaba.fastjson2.JSON
import com.skywo.demo1.common.result.RF
import org.springframework.security.core.Authentication
import org.springframework.security.web.authentication.AuthenticationSuccessHandler
import javax.servlet.http.HttpServletRequest
import javax.servlet.http.HttpServletResponse

class MyAuthenticationSuccessHandler : AuthenticationSuccessHandler {
    override fun onAuthenticationSuccess(
        request: HttpServletRequest,
        response: HttpServletResponse,
        authentication: Authentication
    ) {
        // 获取用户身份信息
        val principal = authentication.principal
        //返回响应
        response.contentType = "application/json;charset=UTF-8"
        response.writer.println(JSON.toJSONString(RF.success(principal)))
    }
}